import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashMap;

import leesoft.configuration.core.DBToolKit;


public class SQLExecute {
	public static void main(String[] args) throws IOException {
		HashMap<String,String> configMap=new HashMap<String,String>();
		try{
			for(int i=0;i<args.length;i=i+2){
				String key=args[i];
				String value=args[i+1];
				configMap.put(key, value);
			}
			String connectionString=configMap.get("-c");
			String driver=configMap.get("-d");
			String username=configMap.get("-u");
			String password=configMap.get("-p");
			String input=configMap.get("-i");
			String batch=configMap.get("-b");
			String output=configMap.get("-o");
			String cp=configMap.get("-cp");
			if(output==null){
				output="failedBatch.txt";
			}
			if(cp==null){
				cp="UTF-8";
			}
			int batchSize=1000;
			if(batch!=null){
				batchSize=Integer.parseInt(batch);
			}
			DBToolKit dbt=new DBToolKit(driver,connectionString,username,password,cp);
			File file=new File(output);
			FileWriter writer=new FileWriter(file,true);
			dbt.executeOn(input, batchSize,writer);
		}catch(Exception e){
			System.out.println("Error Use!");
			e.printStackTrace();
		}
	}
}
